/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.CosBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Zimlet;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.zimlet.ZimletException;
/*     */ import com.zimbra.cs.zimlet.ZimletUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ModifyZimlet
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  43 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*     */     
/*  45 */     Element z = request.getElement("zimlet");
/*     */     
/*  47 */     Element a = z.getOptionalElement("acl");
/*  48 */     if (a != null) {
/*  49 */       doAcl(zsc, context, z);
/*     */     }
/*  51 */     Element s = z.getOptionalElement("status");
/*  52 */     if (s != null) {
/*  53 */       doStatus(zsc, context, z);
/*     */     }
/*  55 */     Element p = z.getOptionalElement("priority");
/*  56 */     if (p != null) {
/*  57 */       doPriority(zsc, context, z);
/*     */     }
/*  59 */     Element response = zsc.createElement(AdminConstants.MODIFY_ZIMLET_RESPONSE);
/*  60 */     return response;
/*     */   }
/*     */   
/*     */   void doAcl(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
/*  64 */     String name = z.getAttribute("name");
/*  65 */     Element a = z.getElement("acl");
/*  66 */     String cosName = a.getAttribute("cos", null);
/*  67 */     if (cosName == null) { return;
/*     */     }
/*  69 */     Cos cos = Provisioning.getInstance().get(Key.CosBy.name, cosName);
/*  70 */     if (cos == null)
/*  71 */       throw AccountServiceException.NO_SUCH_COS(cosName);
/*  72 */     checkRight(zsc, context, cos, Rights.Admin.R_manageZimlet);
/*     */     
/*  74 */     String acl = a.getAttribute("acl", null);
/*  75 */     if (acl == null)
/*  76 */       throw ServiceException.INVALID_REQUEST("missing acl attribute", null);
/*  77 */     acl = acl.toLowerCase();
/*     */     try {
/*  79 */       if (acl.equals("grant")) {
/*  80 */         ZimletUtil.activateZimlet(name, cosName);
/*  81 */       } else if (acl.equals("deny")) {
/*  82 */         ZimletUtil.deactivateZimlet(name, cosName);
/*     */       } else {
/*  84 */         throw ServiceException.INVALID_REQUEST("invalid acl setting " + acl, null);
/*     */       }
/*     */     } catch (ZimletException ze) {
/*  87 */       throw ServiceException.FAILURE("cannot modify acl", ze);
/*     */     }
/*     */   }
/*     */   
/*     */   void doStatus(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
/*  92 */     String name = z.getAttribute("name");
/*     */     
/*  94 */     Zimlet zimlet = Provisioning.getInstance().getZimlet(name);
/*  95 */     if (z == null) {
/*  96 */       throw AccountServiceException.NO_SUCH_ZIMLET(name);
/*     */     }
/*  98 */     Element s = z.getElement("status");
/*  99 */     String val = s.getAttribute("value", null);
/* 100 */     if (val == null) return;
/* 101 */     boolean status = val.equalsIgnoreCase("enabled");
/*     */     
/* 103 */     Map<String, String> attrRightNeeded = new HashMap();
/* 104 */     attrRightNeeded.put("zimbraZimletEnabled", status ? "TRUE" : "FALSE");
/* 105 */     checkRight(zsc, context, zimlet, attrRightNeeded);
/*     */     try
/*     */     {
/* 108 */       ZimletUtil.setZimletEnable(name, status);
/*     */     } catch (ZimletException ze) {
/* 110 */       throw ServiceException.FAILURE("cannot modify status", ze);
/*     */     }
/*     */   }
/*     */   
/*     */   void doPriority(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
/* 115 */     String name = z.getAttribute("name");
/*     */     
/* 117 */     Zimlet zimlet = Provisioning.getInstance().getZimlet(name);
/* 118 */     if (zimlet == null) {
/* 119 */       throw AccountServiceException.NO_SUCH_ZIMLET(name);
/*     */     }
/* 121 */     Element p = z.getElement("priority");
/* 122 */     int val = (int)p.getAttributeLong("value", -1L);
/* 123 */     if (val == -1) { return;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 130 */     Map<String, String> attrRightNeeded = new HashMap();
/* 131 */     attrRightNeeded.put("zimbraZimletPriority", null);
/*     */     
/* 133 */     List<Zimlet> allZimlets = Provisioning.getInstance().listAllZimlets();
/* 134 */     for (Zimlet zl : allZimlets) {
/* 135 */       checkRight(zsc, context, zl, attrRightNeeded);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 141 */     ZimletUtil.setPriority(name, val);
/*     */   }
/*     */   
/*     */ 
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 147 */     relatedRights.add(Rights.Admin.R_manageZimlet);
/* 148 */     relatedRights.add(Rights.Admin.R_modifyZimlet);
/* 149 */     notes.add("For acl: needs " + Rights.Admin.R_manageZimlet.getName() + " on cos.");
/* 150 */     notes.add("For status: needs right to set zimbraZimletEnabled on the zimlet");
/* 151 */     notes.add("For priority: needs right to set zimbraZimletPriority on *all* zimlets, because potentially the attribute can be modified on all zimlets.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/ModifyZimlet.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */